﻿using System;
using System.Windows.Forms;
using NanoERP.Infrastructure;
using NanoERP.Business.BaseInfo;
using NanoERP.Model;
using System.Collections.Generic;
using NanoERP.Common;

namespace NanoERP.BaseInfo
{
    //[Module("FrmSelectLogistics")]
    public partial class FrmSelectLogistics : ModuleForm
    {
        readonly LogisticsinfoBLL _logisticsBll;
        readonly Dictionary<long, string> _dicSelected;

        /// <summary>
        /// 物流信息
        /// </summary>
        public FrmSelectLogistics()
        {
            InitializeComponent();

            _logisticsBll = new LogisticsinfoBLL();
            _dicSelected = new Dictionary<long, string>();

            QueryInfo();
        }

        /// <summary>
        /// 
        /// </summary>
        void QueryInfo()
        {
            dgvList.AutoGenerateColumns = false;
            dgvList.DataSource = _logisticsBll.Query(txtKey.Text.Trim());
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (dgvList.CurrentRow == null)
            {
                MessageBox.Show(@"没有选择物流公司，请重新检索后选择记录！", @"提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            var vv = dgvList.CurrentRow.DataBoundItem as Clientlogisticsinfo;
            _dicSelected.Add(vv.Id, vv.Clientname);

            this.Tag = _dicSelected;
            this.DialogResult = DialogResult.OK;
        }

        private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
                return;

            btnSelect_Click(null, null);
        }

        private void dgvList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            ControlUtil.DataGridRowPostPaint(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            var f = new FrmLogisticsEdit();
            if (f.ShowDialog() == DialogResult.OK)
            {
                QueryInfo();
            }
        }

        private void txtKey_TextChanged(object sender, EventArgs e)
        {
            QueryInfo();
        }
    }
}
